<template>
	<view>
		<u-sticky style="top: 0" v-if="tabs.length > 1">
			<view
				style="background-color: #fff;padding: 8px;border-top: 1px solid #F3F5F9; border-bottom: 1px solid #F3F5F9;">
				<u-tabs :scrollable='false' :list="tabs" @click="(item) => {currentTab = item}"></u-tabs>
			</view>
		</u-sticky>

		<view v-if="currentTab.value == 'base'">
			<view style="background-color: #fff;">
				<u-cell-group>
					<u-cell title="咨询类型" :value="consultant.commentTypeLabel || '--'"></u-cell>
					<u-cell title="咨询编号" :value="consultant.code"></u-cell>
					<u-cell title="咨询区域" :value="consultant.areaName"></u-cell>
					<u-cell title="咨询人姓名" :value="consultant.commentUser | desensitizedName"></u-cell>
					<u-cell title="咨询人联系方式" :value="consultant.commentTel | desensitizedPhone"></u-cell>
					<u-cell title="发起时间" :value="consultant.whenCreated"></u-cell>
					<u-cell title="咨询标题" :value="consultant.commentTitle"></u-cell>
					<u-cell title="咨询内容">
						<template slot='label'>
							{{consultant.commentInfo}}
							<template v-if="consultant.fileUrls && consultant.fileUrls.length > 0">
							 <u-album :urls="consultant.fileUrls"></u-album>
							 </template>
						</template>
					</u-cell>
				</u-cell-group>
			</view>

		</view>

		<view v-else-if="currentTab.value == 'reply'">
			<view style="background-color: #fff;">
				<u-cell-group>
					<u-cell title="回复人" :value="consultant.consultationReply.replyUserName"></u-cell>
					<u-cell title="回复时间" :value="consultant.consultationReply.whenCreated"></u-cell>
					<u-cell title="回复结果" :value="statusMap[consultant.consultationReply.replyStatus] || '--'"></u-cell>
					<u-cell title="回复内容" :label="consultant.consultationReply.replyInfo"></u-cell>
				</u-cell-group>
			</view>
		</view>

		<view v-else-if="currentTab.value == 'audit'">
			<view style="background-color: #fff;">
				<u-cell-group>
					<u-cell title="审核人" :value="consultant.consultationAudit.auditUserName"></u-cell>
					<u-cell title="审核时间" :value="consultant.consultationAudit.whenCreated"></u-cell>
					<u-cell title="审核结果" :value="statusMap[consultant.consultationAudit.auditStatus] || '--'"></u-cell>
					<u-cell title="审核内容" :label="consultant.consultationAudit.auditInfo"></u-cell>
				</u-cell-group>
			</view>
		</view>

		<view v-else-if="currentTab.value == 'satisfactionInfo'">
			<template v-if="consultant.satisfactionEvaluated">
				<satisfactionInfo :satisfactionLog='satisfactionLog'></satisfactionInfo>
			</template>
			<u-empty v-else text='暂无评价'></u-empty>
		</view>
	</view>
</template>

<script>
	import satisfactionInfo from './satisfactionInfo.vue'
	export default {
		components: {
			satisfactionInfo
		},
		props: {
			consultant: {
				require: true
			}
		},
		watch: {
			consultant: {
				immediate: true,
				handler: function(val) {
					if(val.satisfactionEvaluated){
							this.getSatisfactionLog()
					}
				}
			}
		},
		computed: {
			tabs: function() {
				//[{name: '基础信息', value:'base'}, {name: '满意度信息', value: 'satisfactionInfo'}]
				let base = [{
					name: '基础信息',
					value: 'base'
				}]
				if(['TO_BE_REPLIED', 'RE_REPLIED'].indexOf(this.consultant.commentStatus) < 0 ){
					if (this.consultant.consultationReply) {
						base.push({
							name: '回复信息',
							value: 'reply'
						})
					}
					if('TO_BE_REVIEWED' != this.consultant.commentStatus){
							if (this.consultant.consultationAudit) {
								base.push({
									name: '审核信息',
									value: 'audit'
								})
							}
					}
				}
				
				if (this.consultant.satisfactionEvaluated) {
					base.push({
						name: '满意度',
						value: 'satisfactionInfo'
					})
				}
				return base
			}
		},
		data() {
			return {
				currentTab: {
					name: '基础信息',
					value: 'base'
				},

				satisfactionLog: {},
				statusMap: {
					TO_AUDIT: '提交审核',
					TO_ISOLATION: '提交隔离',
					APPROVED: '通过',
					REFUSED: '驳回',
					ISOLATION: '隔离'
				}
			}
		},
		methods: {
			getSatisfactionLog: function() {
				this.$api.satisfactionLog({
					icType: 'MC',
					consultationId: this.consultant.id
				}).then(res => {
					if (res.success) {
						this.satisfactionLog = res.result || {}
					} else {
						toast(res.message)
					}
				}).catch(err => {
					console.log('searchHis error', err)
					toast('获取满意度评价失败！')
				})
			},
		}
	}
</script>

<style>

</style>